package com.sunnada.btfvilg.controller;

import com.sunnada.btfvilg.common.response.Result;
import com.sunnada.btfvilg.common.response.ResultFactory;
import com.sunnada.btfvilg.model.request.UserParamVo;
import com.sunnada.btfvilg.model.request.UserRegParamVo;
import com.sunnada.btfvilg.model.response.UserVo;
import com.sunnada.btfvilg.service.DeliverymanService;
import com.sunnada.btfvilg.service.SiteService;
import com.sunnada.btfvilg.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;


/**
 * 登录相关的接口
 */
@RestController
@RequestMapping("loginAndReg")
@Api(tags = "登录注册接口")
public class LoginController {

    @Autowired
    private UserService userService;

    @Autowired
    private DeliverymanService deliverymanService;

    @Autowired
    private SiteService siteService;

    @PostMapping("/userLogin")
    @ApiOperation(value = "用户登录", httpMethod = "POST")
    public Result<UserVo> userLogin(@Validated @RequestBody UserParamVo user) {
        UserVo login = userService.login(user);
        return ResultFactory.success("登录成功",login);
    }

    @PostMapping("/userRegister")
    @ApiOperation(value = "用户注册", httpMethod = "POST")
    public Result<UserVo> userRegister(@Validated @RequestBody UserRegParamVo userRge) {
        UserVo reg = userService.userRegister(userRge);
        return ResultFactory.success("注册成功",reg);
    }

    @PostMapping("/DeliManLogin")
    @ApiOperation(value = "快递员登录", httpMethod = "POST")
    public Result<UserVo> DeliManLogin(@Validated @RequestBody UserParamVo user) {
        UserVo login = deliverymanService.login(user);
        return ResultFactory.success("登录成功",login);
    }

    @PostMapping("/adminLogin")
    @ApiOperation(value = "管理员登录", httpMethod = "POST")
    public Result<UserVo> adminLogin(@Validated @RequestBody UserParamVo user) {
        UserVo login = userService.adminLogin(user);
        return ResultFactory.success("登录成功",login);
    }

    @PostMapping("/siteLogin")
    @ApiOperation(value = "网点登录", httpMethod = "POST")
    public Result<UserVo> siteLogin(@Validated @RequestBody UserParamVo user) {
        UserVo login = siteService.siteLogin(user);
        return ResultFactory.success("登录成功",login);
    }

}
